package org.budo.redis.jdbc.driver.statement.string;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.budo.jdbc.driver.resultset.impl.ObjectArrayResultSet;
import org.budo.redis.jdbc.driver.BudoRedisJdbcConnection;
import org.budo.redis.jdbc.driver.BudoRedisJdbcPreparedStatement;
import org.budo.redis.jdbc.driver.executor.RedisStatementExecutor;
import org.budo.redis.jdbc.driver.statement.AbstractRedisStatement;

/**
 * @author lmw
 */
public class INCRBYFLOAT extends AbstractRedisStatement {
    @Override
    public void execute(PreparedStatement preparedStatement) throws SQLException{
        byte[] key = this.parameter(0, preparedStatement);
        Double value = this.parameterNumber(1, preparedStatement).doubleValue();

        RedisStatementExecutor statementExecutor = ((BudoRedisJdbcConnection) preparedStatement.getConnection()).getStatementExecutor();
        Double incrByFloat = statementExecutor.incrByFloat(key, value);

        ResultSet resultSet = new ObjectArrayResultSet(new String[] { "incrByFloat" }, new Object[] { incrByFloat });
        ((BudoRedisJdbcPreparedStatement) preparedStatement).setResultSet(resultSet);
    }
}